package com.demo.camel04.activemq;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.PropertyConfigurator;

import javax.jms.ConnectionFactory;

public class ActiveMQDemo {

    public static void main(String[] args) throws Exception {

        // 日志
        PropertyConfigurator.configure("src/conf/log4j.properties");
        PropertyConfigurator.configureAndWatch("src/conf/log4j.properties", 1000);

        CamelContext context = new DefaultCamelContext();
        context.start();

        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER, ActiveMQConnectionFactory.DEFAULT_PASSWORD, "tcp://192.168.99.100:61616");

        context.addComponent("activemq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));


        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {

                from("file:inbox?noop=true").to("activemq:queue:my_queue");

            }
        });


        // 通用没有具体业务意义的代码，只是为了保证主线程不退出
        synchronized (ActiveMQDemo.class) {
            ActiveMQDemo.class.wait();
        }
    }
}
